class EXAMPLE5
-- This example show how use tabs and many other controls.

insert
	IUP_INTERFACE

create {ANY}
   make

feature {ANY}

	ml: IUP_MULTILINE
	l4: IUP_LABEL
	pb: IUP_PROGRESS_BAR

	lm: LOOP_STACK
   counter: INTEGER
   time: MICROSECOND_TIME

	make
		local
			gui: IUP
			i: STRING
			w: IUP_DIALOG
			t: IUP_TABS
			v1, v2, v3: IUP_VBOX
			h1: IUP_HBOX
			b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12: IUP_BUTTON
			im: IUP_IMAGE
			l1, l2, l3: IUP_LABEL
			s1: IUP_VAL
			lt: IUP_LIST
			fl: IUP_FILL
			al: IUP_ANIMATED_LABEL
			d: IUP_DATE_PICK
			c: IUP_CALENDAR
			tx1: IUP_TEXT
			sb1: IUP_SPIN_BOX
			scll: IUP_SCROLL_BOX
			frm: IUP_FRAME
			ml1: IUP_MULTILINE
			sb: IUP_SPLIT
		do
			gui := iup_open
			gui.load_images
			gui.load_iup_controls

			-- Controls at first tab
			---------------------------------
			
			create im.image({FAST_ARRAY2[INTEGER] 10, 10, << 15, 15, 15, 15, 15, 15, 15, 15, 15, 15;
																	 	    15, 15, 15,  1,  1,  1,  1, 15, 15, 15;
																		    15, 15, 15,  1, 15, 15, 15, 15, 15, 15;
																		    15, 15, 15,  1, 15, 15, 15, 15, 15, 15;
																		    15, 15, 15,  1, 15, 15, 15, 15, 15, 15;
																		    15, 15, 15,  1,  1,  1, 15, 15, 15, 15;
																		    15, 15, 15,  1, 15, 15, 15, 15, 15, 15;
																		    15, 15, 15,  1, 15, 15, 15, 15, 15, 15;
																		    15, 15, 15,  1, 15, 15, 15, 15, 15, 15;
																		    15, 15, 15, 15, 15, 15, 15, 15, 15, 15 >>})
			im.set_widget_name("my_image")

			create b1.button("Launch an alarn")
			b1.set_cb_action(agent alarm(?))
			create b2.button("Select a file")
			b2.set_cb_action(agent file(?))
			create b3.button("Select a color")
			b3.set_cb_action(agent color(?))
			create b4.button("Write a message")
			b4.set_cb_action(agent get_message(?))
			create b5.button("Select an option")
			b5.set_cb_action(agent list(?))
			create b6.button("Preferences")
			b6.set_cb_action(agent param(?))
			create b7.button("Font")
			b7.set_image("my_image")
			b7.set_cb_action(agent font(?))
			create b8.button("A message")
			b8.set_cb_action(agent message(?))
			create b9.button("Color dialog")
			b9.set_cb_action(agent color_dialog(?))
			create b10.button("A message dialog")
			b10.set_cb_action(agent message_dlg(?))
			create fl.fill
			create al.animated_label_empty
			al.set_animation("IUP_CircleProgressAnimation")
			create ml.multiline
			ml.set_expand("YES")

			create v1.vbox({ARRAY[IUP_WIDGET] 1, << b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, fl, al >>})
			v1.set_alignment("ACENTER")
			v1.set_gap(10)
			v1.set_margin(10, 10)
			v1.set_normalize_size("HORIZONTAL")

			create h1.hbox({ARRAY[IUP_WIDGET] 1, << v1, ml >>})

			-- Controls at second tab
			-----------------------------------------
			
			create l1.label("Age")
			create l2.label("City")
			create l3.label("Date")
			create d.date_pick
			create s1.horizontal_val
			create lt.list
			lt.set_drop_down(True)
			lt.set_size(80, 12)
			create c.calendar

			create v2.vbox({ARRAY[IUP_WIDGET] 1, << d, l1, s1, l2, lt, l3,
																 c >>})
			v2.set_gap(10)
			v2.set_margin(10, 10)

			-- Controls at third tab
			-----------------------------------------
			
			create tx1.text
			tx1.set_value("0")
			tx1.set_spin(True)
			create l4.label("0")
			l4.set_size(40, 12)
			l4.set_alignment("ACENTER", "ACENTER")
			create sb1.spin_box(l4)
			sb1.set_cb_spin(agent spin_click(?, ?))
			create frm.frame(sb1)
			frm.set_title("Spin-label")
			create ml1.multiline
			ml1.set_expand("YES")
			ml1.set_size(550, 350)
			create pb.progress_bar
			create b11.button("Starts")
			b11.set_cb_action(agent progress_bar(?))
			create b12.button("Progress dialog")
			b12.set_cb_action(agent progress_dialog(?))
			create scll.scroll_box(ml1)

			create v3.vbox({ARRAY[IUP_WIDGET] 1, << tx1, sb1, pb, b11, b12 >>})
			v3.set_gap(10)
			v3.set_margin(10, 10)

			create sb.split(v3, scll)
			--sb.set_show_grip("LINES")
			sb.set_min_and_max(250, 750)
			sb.set_value(500)

			-- Create the tabs
			-------------------------------

			create t.tabs({ARRAY[IUP_WIDGET] 1, << h1, v2, sb >>})
			t.set_tab_n_title("Buttons", 0)
			t.set_tab_n_title("List, Slider and Date", 1)
			t.set_tab_n_title("Split", 2)

			-- Create the window.
			-------------------------
			
	      create w.dialog(t)
			w.set_title("Controls test")
			w.set_predefined_size("HALF", "250")
			w.set_widget_name("window")
			i := w.show

			-- Start the animation.
			al.start

			-- Add items at list.
			lt.append_item("London")
			lt.append_item("Madrid")
			lt.append_item("New York")
			lt.append_item("Paris")
			lt.append_item("Milan")
			lt.append_item("Tokyo")
			lt.append_item("Buenos Aires")
			lt.set_value_string("Milan")
			
			gui.main_loop
			gui.close
		end

	alarm (widget: IUP_WIDGET): STRING
		local
			r: INTEGER
			al: IUP_ALARM
		do
			create al.alarm_three_buttons("Alarm", "Select a button", "1",
													"2", "3")

			r := al.launch

			if r.is_equal(1) then
				ml.append("You selected the first button; %N")
			elseif r.is_equal(2) then
				ml.append("You selected the second button; %N")
			elseif r.is_equal(3) then
				ml.append("You selected the third button; %N")
			end				
			
			Result := "IUP_DEFAULT"
		end

	file (widget: IUP_WIDGET): STRING
		local
			tup: TUPLE[INTEGER, STRING]
			fl: IUP_GET_FILE
		do
			create fl.get_file("~/", "*.txt")

			tup := fl.launch

			if tup.item_1.is_equal(0) then
				ml.append(tup.item_2)
				ml.append("%N")
			end

			Result := "IUP_DEFAULT"
		end

	color (widget: IUP_BUTTON): STRING
		local
			tup: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
			gc: IUP_GET_COLOR
		do
			create gc.get_color_with_initial(0, 0, 0)

			tup := gc.launch_predefined_xy("IUP_CENTER", "IUP_CENTER")

			if tup.item_1.is_equal(1) then
				ml.set_rgb_foreground_color(tup.item_2, tup.item_3, tup.item_4)
			end

			Result := "IUP_DEFAULT"
		end

	get_message (widget: IUP_BUTTON): STRING
		local
			tup: TUPLE[INTEGER, STRING]
			gt: IUP_GET_TEXT
		do
			create gt.get_text_with_initial("Write a message", "...", 40)

			tup := gt.launch

			if not tup.item_1.is_equal(0) then
				ml.append(tup.item_2)
				ml.append("%N")
			end

			Result := "IUP_DEFAULT"
		end

	list (widget: IUP_BUTTON): STRING
		local
			ld: IUP_LIST_DIALOG
			a: ARRAY[STRING]
			tup: TUPLE[INTEGER, STRING]
		do
			a := {ARRAY[STRING] 1, << "Uno", "Dos", "Tres", "Cuatro", "Cinco",
											  "Seis", "Siete", "Ocho", "Nueve", "Diez" >>}
			
			--create ld.list_dialog_simple("Select", a, 1, 1, 1)
			create ld.list_dialog_multiple("Select", a, 1, 5)

			tup := ld.launch

			ml.append(tup.item_2)
			ml.append("%N")

			Result := "IUP_DEFAULT"
		end


	param (widget: IUP_BUTTON): STRING
		local
			i: INTEGER
			gp: IUP_GET_PARAM
			p: POINTER
			d1, d2, d3, d4, d5: INTEGER
			dr1, dr2, dr3: REAL_32
		do
			d1 := 1.to_integer_32
			d2 := 3456.to_integer_32
			d3 := 192
			d4 := 1
			d5 := 2

			dr1 := 3.543.force_to_real_32
			dr2 := 0.5.force_to_real_32
			dr3 := 90.to_real_32
			
			create gp.get_param ("Preferences", agent preferences(?, ?, ?), p)
			gp.add_buttons_parameter (", MyCancel, Help!")
			gp.add_boolean_parameter ("Boolean:", "No,Yes", "", $d1)
			gp.add_integer_parameter ("Integer:", "", "", $d2)
			gp.add_real_parameter ("Real 1:", "", "", $dr1)
			gp.add_separator ("Sep1")
			gp.add_integer_parameter ("Integer:", "0,255", "", $d3)
			gp.add_real_parameter ("Real 2:", "-1.5,1.5,0.05", "", $dr2)
			gp.add_separator ("Sep2")
			gp.add_angle_real_parameter ("Angle:", "0,360", "", $dr3)
			gp.add_string_parameter ("String:", "", "", "string text".to_external)
			gp.add_radio_parameter ("Options:", "item0|item1|item2", "", $d4)
			gp.add_list_parameter ("List:", "item0|item1|item2|item3|item4|item5|item6", "", $d5)
			gp.add_file_parameter ("File:", "OPEN|*.bmp;*.jpg|CURRENT|NO|NO", "", "test.jpg".to_external)
			gp.add_color_parameter ("Color", "", "255 0 128".to_external)
			gp.add_font_parameter ("Font", "", "Courier, 24".to_external)
			gp.add_separator ("Sep3")
			gp.add_multiline_parameter ("Multiline:", "", "", "second text%Nsecond line".to_external)

			i := gp.launch
						 
			Result := "IUP_DEFAULT"
		end
	
	preferences (dialog: IUP_GET_PARAM; index: INTEGER; data: POINTER): INTEGER
		local
			dat: STRING
		do
			--io.put_string("Hello %N")
			dat := dialog.get_parameter_value_at(index)
			io.put_string(dat)
			io.put_string("%N")

			Result := 1
		end

	font (widget: IUP_BUTTON): STRING
		local
			fd: IUP_FONT_DIALOG
			str: STRING
			status: INTEGER
		do
			create fd.font_dialog
			str := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")

			status := fd.get_status

			if status.is_equal(1) then
				ml.set_font(fd.get_value)
			end
			
			Result := "IUP_DEFAULT"
		end

	message (widget: IUP_BUTTON): STRING
		local
			ms: IUP_MESSAGE
		do
			create ms.message("A message", "Your message")
			Result := "IUP_DEFAULT"
		end

	color_dialog (widget: IUP_BUTTON): STRING
		local
			cd: IUP_COLOR_DIALOG
			rs: STRING
			status: INTEGER
			tup: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
		do
			create cd.color_dialog
			rs := cd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")

			status := cd.get_status

			if status.is_equal(1) then
				tup := cd.get_value
				ml.set_rgb_foreground_color(tup.item_1, tup.item_2, tup.item_3)
			end

			cd.destroy
			
			Result := "IUP_DEFAULT"
		end

	message_dlg (widget: IUP_BUTTON): STRING
		local
			mdlg: IUP_MESSAGE_DIALOG
			i: STRING
			r: INTEGER
		do
			create mdlg.message_dialog
			mdlg.set_title("A message dialog")
         mdlg.set_value("Are you sure?")
			mdlg.set_buttons("YESNOCANCEL")
			mdlg.set_dialog_type("QUESTION")
			mdlg.set_parent_dialog("window")

			i := mdlg.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")

			r := mdlg.get_button_response

			ml.append(r.to_string)
			ml.append("%N")
			
			Result := "IUP_DEFAULT"
		end

	progress_bar (widget: IUP_BUTTON): STRING
		local
			cl: INTEGER
			pr: REAL_64
			ls: STRING
		do
			from
            cl := 0
         until
            cl > 1000
         loop
				pr := cl.to_real_64 / 1000.to_real_64
				pb.set_value(pr)
				ls := iup_open.loop_step
				cl := cl + 1
         end

			Result := "IUP_DEFAULT"
		end

	progress_dialog (widget: IUP_BUTTON): STRING
		local
			pdlg: IUP_PROGRESS_DIALOG
			cl: INTEGER
			ls, i: STRING
		do
			create pdlg.progress_dialog
			pdlg.set_total_count(500)
			i := pdlg.show

			from
            cl := 0
         until
            cl > 1000
         loop
				pdlg.increment_one
				ls := iup_open.loop_step
				cl := cl + 1
         end

			pdlg.hide
			pdlg.destroy
			
			Result := "IUP_DEFAULT"
		end

	spin_click (wgt: IUP_SPIN_BOX; inc: INTEGER): STRING
		local
			lint: INTEGER
		do
			if l4.get_title.is_integer then
				lint := l4.get_title.to_integer + inc
				l4.set_title(lint.to_string)
			end
			
			Result := "IUP_DEFAULT"
		end

end -- class EXAMPLE5
